home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / misc / cases.sty (.txt) < prev    next >
LaTeX Document  |  1993-08-30  |  4KB  |  105 lines

  1. %  C A S E S . S T Y             ver 1.0
  2. %  Copyright (C) 1993 by Donald Arseneau
  3. %  These macros may be freely transmitted, reproduced, or modified 
  4. %  provided that this notice is left intact.  Sub-equation numbering
  5. %  is based on subeqn.sty by Stephen Gildea.
  6. %  LaTeX environment "numcases" to produce multi-case equations with
  7. %  a separate equation number for each case.  Also, "subnumcases"
  8. %  gives each case numbered with the equation number plus a letter 
  9. %  [8a, 8b, etc.]   The syntax is
  10. %  \begin{numcases}{left_side}
  11. %  case_1 & explanation \\
  12. %  case_2 & explanation \\
  13. %  ...
  14. %  case_n & explanation
  15. %  \end{numcases}
  16. %  Each case is a math formula, and each explanation is a piece of
  17. %  lr mode text (which may contain math mode).  The explanations are
  18. %  optional.  Equation numbers are inserted automatically, just as for
  19. %  the eqnarray environment.  In particular, the \nonumber command 
  20. %  suppresses an equation number, and the \label command allows 
  21. %  reference to a particular equation.  In a subnumcases environment, 
  22. %  a \label in the left_side of the equation gives the overall equation 
  23. %  number, without any letter.
  24. % - - - - -   
  25. %  A simple example is:
  26. %    \begin{numcases}{|x|=}
  27. %    x, & for $x \geq 0$\\
  28. %    -x, & for $x < 0$
  29. %    \end{numcases}
  30. %                    / x   for x > 0              (1)
  31. %             |x| = <            -
  32. %                    \ -x  for x < 0              (2)
  33. % - - - - -   
  34. %  Another:
  35. %    \begin{subnumcases}{f(x)=\label{f(x)}}
  36. %    1/3 & if $0 < x < 1$;\\
  37. %    2/3 & if $3 < x < 4$;\label{.6666}\\
  38. %    0   & elsewhere.
  39. %    \end{subnumcases}
  40. %                   /  1/3   if 0 < x < 1;      (18.23a)
  41. %                   |
  42. %           f(x) = <   2/3   if 3 < x < 4;      (18.23b)   
  43. %                   |
  44. %                   \  0     elsewhere.         (18.23c)
  45. %  and \ref{f(x)} will then give (18.23) while \ref{.6666} gives (18.23b)
  46. %  - - -  begin definitions - - - 
  47. \def\numcases#1{$$%
  48.  \setbox\z@\hbox{\advance\c@equation\@ne\let\@currentlabel\theequation % local
  49.   $\displaystyle {#1}\m@th\mskip\medmuskip$}%
  50. \numc@setsub
  51. \dimen@ii\displaywidth
  52. \setbox\tw@\vbox\bgroup
  53.  \stepcounter{equation}\let\@currentlabel\theequation
  54.  \global\@eqnswtrue\m@th
  55.  \tabskip\@centering\let\\\@eqncr
  56.  \halign to\dimen@ii
  57.  \bgroup
  58.    \kern\wd\z@ \kern13\p@ \global\@eqcnt\@ne$\displaystyle\tabskip\z@{##}$\hfil 
  59.    &\global\@eqcnt\tw@ \quad ##\unskip \hfil\tabskip\@centering
  60.    &\llap{##}\tabskip\z@\cr}
  61. \def\endnumcases{\@@eqncr
  62.  \egroup % end \halign, which does not contain first column or brace
  63.  \global\advance\c@equation\m@ne 
  64.  \unskip\unpenalty\unskip\unpenalty
  65.  \setbox\z@\lastbox \nointerlineskip \copy\z@ % grab last line, then put it back
  66.  \g@tboxedwidth\z@ % box \z@ destroyed, width of columns -> \dimen@i
  67. \egroup% end \vbox (\box\tw@)
  68. \hbox to\displaywidth{% assemble the whole equation
  69.  \hskip\@centering \hbox to\dimen@i{$\displaystyle \box\z@ % parameter #1
  70.   \dimen@\ht\tw@ \advance\dimen@\dp\tw@ % get size of brace
  71.   \left\{\vcenter to\dimen@{\vfil}\right.\n@space % make brace
  72.   $\hfil}\hskip\@centering % finished first part (filled whole line)
  73.  \kern-\displaywidth $\vcenter{\box\tw@}$% overlay the alignment
  74. }% end the \hbox
  75. \numc@resetsub
  76. $$\global\@ignoretrue}
  77. % Get width of all boxes on a line, ignoring the glue between them.
  78. % Return total width in \dimen@i (global).
  79. \def\g@tboxedwidth#1{\setbox#1\hbox{\unhbox#1\global\dimen@i\z@ 
  80.   \G@tBoxedWidth}}
  81. \def\G@tBoxedWidth{\unskip\unskip\unskip \setbox\z@\lastbox 
  82.  \ifvoid\z@\else \global\advance\dimen@i\wd\z@ \expandafter\G@tBoxedWidth \fi}
  83. \let\numc@setsub\relax
  84. \let\numc@resetsub\relax
  85. \def\subnumcases{\let\numc@setsub\subequations
  86.   \let\numc@resetsub\endsubequations\numcases}
  87. \let\endsubnumcases\endnumcases
  88. % These versions of subequations follow the style of Gildea's subeqn.sty,
  89. % but are rewritten.
  90. \def\subequations{\refstepcounter{equation}%
  91.   \edef\@savedequation{\the\c@equation}%
  92.   \let\@tempa\protect % *
  93.   \def\protect{\noexpand\protect\noexpand}% *
  94.   \edef\theequation{\theequation\noexpand\alph{equation}}%
  95.   \let\protect\@tempa % *
  96.   \global\c@equation\z@}
  97. \def\endsubequations{%
  98.   \setcounter{equation}{\@savedequation}%
  99.   \global\@ignoretrue}
  100. % Send problem reports to asnd@Reg.TRIUMF.CA
  101. % test integrity:
  102. % brackets:  round, square, curly, angle:   () [] {} <>
  103. % backslash, slash, vertical, at, dollar, and: \ / | @ $ &
  104. % hat, grave, acute (apostrophe), quote, tilde, under:   ^ ` ' " ~ _
  105.